package org.leon.controller;

import org.leon.pojo.User;
import org.leon.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/demo")
public class DemoController {


    private UserService userService;

    @Autowired
    public DemoController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/hello")
    @ResponseBody
    public String hello() {
        return "Hello World";
    }

    @GetMapping("/list")
    public ModelAndView queryList(){
        ModelAndView mv = new ModelAndView("list");
        List<User> list = userService.findAll();
        mv.addObject("resultList", list);
        return mv;
    }
}
